# Contributor: Hani Shawa <hani.shawa@ev-box.com>
# Maintainer: Hani Shawa <hani.shawa@ev-box.com>
pkgname=luacov
_rockname=${pkgname#lua-}
pkgver=0.14.0
pkgrel=1
pkgdesc="simple coverage analysis tool for Lua scripts"
url="https://github.com/keplerproject/luacov"
license="MIT"
arch="noarch"
makedepends="luarocks"
options="!check" # Test dependencies not available
source="$_rockname-$pkgver.tar.gz::https://github.com/keplerproject/luacov/archive/v$pkgver.tar.gz
reporter_fix.lua.patch
"

_luaversions="5.1 5.2 5.3"

for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev luarocks$_v"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."

		luarocks-$lver \
			LUA_INCDIR="$(pkg-config --variable=includedir lua$lver)" \
			LUA_LIBDIR="$(pkg-config --variable=libdir lua$lver)" \
			make --tree=./build \
			"$_rockname-scm-1.rockspec"
			rm "./build/lib/luarocks/rocks-$lver/manifest"
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"

	local path; for path in "lib/luarocks/rocks-$lver" "share/lua/$lver"; do
		mkdir -p "$subpkgdir/usr/${path%/*}"
		mv "$builddir/build/$path" "$subpkgdir/usr/$path/"
	done
}

sha512sums="
44ea158ce597f705d80b9768676e401804daea91b9c2afb146a8d25aae612e895e4f42a29c4b7b3438659c596fa500af5d23b66b7f3477459747ad06ca9b7ffa  luacov-0.14.0.tar.gz
c6896588a1baece398ceccc346f3481151a59d63cff2d5a10be7f14318a65727ba52cb0b5e5f517466d9cd61835bd7c5af4f1c8da9aedb18008a6042f9acd593  reporter_fix.lua.patch
"
